var t = require("../../../../@babel/runtime/helpers/typeof"), e = getApp();

Page({
    data: {
        apply: "-1",
        provicevalue: "",
        cityvalue: "",
        regionvalue: "",
        selectLevel: "",
        selectLevelname: "",
        streetvalue: "",
        level: [],
        provinceoptions: [],
        cityoptions: [],
        regionoptions: [],
        stroptions: [],
        proviceObject: "",
        cityObject: "",
        citys: [],
        district: [],
        regionObject: "",
        districtObject: "",
        proshow: !1,
        cityshow: !1,
        regshow: !1,
        strshow: !1,
        selshow: !1,
        prozoneshow: !1,
        cityzoneshow: !1,
        regzoneshow: !1,
        streetshow: !1,
        username: "",
        password: "",
        name: "",
        agreement: "",
        agreementShow: !1,
        is_open_agreement: "0",
        is_agreement: !1,
        apply_background: "",
        upload_flag: !0,
        apply_switch: !1
    },
    onLoad: function(t) {
        this.cheackRouter(), this.getStatus();
        try {
            var e = JSON.parse(wx.getStorageSync("mailLanguage"));
            if (e && e.area_dividend) {
                var a = e.area_dividend.title || "区域代理";
                wx.setNavigationBarTitle({
                    title: a + "申请"
                });
            }
        } catch (t) {}
    },
    changeAgreement: function(t) {
        this.setData({
            is_agreement: t.detail
        });
    },
    cheackRouter: function() {
        var e = this;
        try {
            var a = function() {
                for (var t, a, i = wx.getStorageSync("yz_basic_info"), s = i.popularize_page.mini.vue_route, o = 0; o < s.length; o++) if ("applyRegionalAgency" == s[o]) return console.log(i.popularize_page.mini.mini_url + "跳转的路径"), 
                wx.showToast({
                    title: "未开启推广权限",
                    duration: 1e3,
                    icon: "none",
                    success: function() {
                        setTimeout(function() {
                            wx.redirectTo({
                                url: i.popularize_page.mini.mini_url
                            });
                        }, 1e3);
                    }
                }), {
                    v: void 0
                };
                e.setData({
                    apply_switch: null !== (t = null === (a = i.plugin_setting.sub_platform) || void 0 === a ? void 0 : a.apply_switch) && void 0 !== t && t
                });
            }();
            if ("object" === t(a)) return a.v;
        } catch (t) {
            console.log(t);
        }
    },
    setExplainFlag: function() {
        this.setData({
            agreementShow: !0
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getAreaDividend: function() {
        var t = this, a = e.getNetAddresss("plugin.area-dividend.api.area-dividend.getAreaDividend");
        e._getNetWork({
            url: a,
            success: function(e) {
                var a = e.data;
                1 === a.result ? (t.setData({
                    dividend: a.data
                }), console.log(t.data.dividend, "数组")) : wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getStatus: function() {
        var t = this, a = e.getNetAddresss("plugin.area-dividend.api.area-dividend.apply-status");
        e._getNetWork({
            url: a,
            success: function(e) {
                if (console.log(e.data, "数据"), 1 === e.data.result) {
                    var a = e.data.data;
                    t.setData({
                        apply: a.apply,
                        agreement: a.agreement,
                        is_open_agreement: a.is_open,
                        tipMsg: e.data.msg
                    }), "" == a.apply_background ? t.setData({
                        upload_flag: !1
                    }) : t.setData({
                        apply_background: a.apply_background
                    }), console.log(t.data.apply, "tplapkfkakfpo"), t.setLogic(t.data.apply);
                } else wx.showToast({
                    title: e.data.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    setLogic: function(t) {
        "0" == t ? console.log("错误") : (1 == t || 2 == t) && (this.initLevel(), this.initData());
    },
    goHome: function() {
        console.log("回去首页"), wx.reLaunch({
            url: "/packageG/index/index"
        });
    },
    initLevel: function() {
        var t = this, a = e.getNetAddresss("plugin.area-dividend.api.area-dividend.can-apply-agent-level");
        return e._getNetWork({
            url: a,
            success: function(e) {
                var a = e.data;
                1 === a.result ? t.setData({
                    level: a.data
                }) : wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    initData: function() {
        console.log("5464655454"), "" == this.data.provinceoptions ? this.getAddressDataInfo() : this.initProvice();
    },
    initProvice: function() {
        var t = this;
        wx.getStorage({
            key: "province",
            success: function(e) {
                t.setData({
                    provinceoptions: e.data || []
                });
            }
        });
    },
    selectProviceHandleShow: function() {
        this.setData({
            proshow: !0
        });
    },
    selectProviceHandle: function(t) {
        console.log(t.currentTarget.dataset.item, "items"), this.setData({
            provicevalue: t.currentTarget.dataset.item.areaname || t.target.dataset.item.areaname,
            proshow: !1,
            proviceObject: t.currentTarget.dataset.item || t.target.dataset.item
        });
        var e = this.data.citys, a = [], i = t.currentTarget.dataset.item.id || t.target.dataset.item.id;
        console.log(i, "id878778");
        for (var s = 0; s < e.length; s++) e[s].parentid == i && (a.push(e[s]), this.setData({
            cityoptions: a
        }));
        console.log(this.data.cityoptions, "城市");
    },
    selectCityHandle: function(t) {
        console.log(t.currentTarget.dataset.item, "items"), this.setData({
            cityvalue: t.currentTarget.dataset.item.areaname || t.target.dataset.item.areaname,
            cityshow: !1,
            cityObject: t.currentTarget.dataset.item || t.target.dataset.item
        });
        var e = this.data.district;
        console.log(e, "545454455554");
        var a = [], i = t.currentTarget.dataset.item.id || t.target.dataset.item.id;
        console.log(i, "id878778");
        for (var s = 0; s < e.length; s++) e[s].parentid == i && (a.push(e[s]), this.setData({
            regionoptions: a
        }));
        console.log(this.data.regionoptions, "64454454554城市");
    },
    selectRegionHandle: function(t) {
        console.log(t.currentTarget.dataset.item, "items");
        var e = t.currentTarget.dataset.item || t.target.dataset.item;
        this.setData({
            regionvalue: e.areaname,
            regshow: !1,
            regionObject: e
        }), this.isStreetShow(e.id);
    },
    getAddressDataInfo: function() {
        var t = this, a = e.getNetAddresss("member.member-address.address");
        e._getNetWork({
            url: a,
            success: function(e) {
                console.log(e.data.data, "数据844884"), 1 === e.data.result ? t.setData({
                    provinceoptions: e.data.data.province,
                    citys: e.data.data.city,
                    district: e.data.data.district
                }) : wx.showToast({
                    title: e.data.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    isMoblie: function(t) {
        return !/^1\d{10}$/.test(t);
    },
    submit: function(t) {
        if (1 != this.data.is_open_agreement || 0 != this.data.is_agreement) {
            var a = t.currentTarget.dataset.bler || t.target.dataset.bler;
            if ("" != this.data.name) if ("" != this.data.phone && null != this.data.phone) if (this.isMoblie(this.data.phone)) wx.showToast({
                title: "请输入正确的手机号",
                icon: "none"
            }); else if ("" != this.data.username && null != this.data.username || this.data.apply_switch) if ("" != this.data.password && null != this.data.password || this.data.apply_switch) if ("" != this.data.selectLevel) if ("" != this.data.provicevalue) {
                var i;
                i = "true" == a ? e.getNetAddresss("plugin.area-dividend.api.area-dividend.apply-again") : e.getNetAddresss("plugin.area-dividend.api.area-dividend.set-agent-apply");
                var s = {
                    username: this.data.username,
                    mobile: this.data.phone,
                    password: this.data.password,
                    real_name: this.data.name
                };
                "0" == this.data.selectLevel.tag ? s.province_id = this.data.proviceObject.id : "1" == this.data.selectLevel.tag ? (s.province_id = this.data.proviceObject.id, 
                s.city_id = this.data.cityObject.id) : "2" == this.data.selectLevel.tag ? (s.province_id = this.data.proviceObject.id, 
                s.city_id = this.data.cityObject.id, s.district_id = this.data.regionObject.id) : "3" == this.data.selectLevel.tag && (s.province_id = this.data.proviceObject.id, 
                s.city_id = this.data.cityObject.id, s.district_id = this.data.regionObject.id, 
                s.street_id = this.data.districtObject.id), s = {
                    data: JSON.stringify(s)
                }, e._getNetWork({
                    url: i,
                    data: s,
                    success: function(t) {
                        console.log(t.data.data, "数据844884"), 1 === t.data.result ? wx.showToast({
                            title: t.data.msg,
                            icon: "none",
                            duration: 1500,
                            success: function() {
                                setTimeout(function() {
                                    wx.navigateBack({
                                        delta: 1
                                    });
                                }, 1500);
                            }
                        }) : wx.showToast({
                            title: t.data.msg,
                            icon: "none"
                        });
                    },
                    fail: function(t) {
                        console.log(t);
                    }
                });
            } else wx.showToast({
                title: "请选择省级区域",
                icon: "none"
            }); else wx.showToast({
                title: "请选择代理类型",
                icon: "none"
            }); else wx.showToast({
                title: "请填写登录密码",
                icon: "none"
            }); else wx.showToast({
                title: "请填写登录账号",
                icon: "none"
            }); else wx.showToast({
                title: "请填写手机号",
                icon: "none"
            }); else wx.showToast({
                title: "请填写姓名",
                icon: "none"
            });
        } else wx.showToast({
            title: "请同意协议",
            icon: "none"
        });
    },
    showCity: function() {
        "" != this.data.provicevalue ? this.setData({
            cityshow: !0
        }) : wx.showToast({
            title: "请选择省级区域",
            icon: "none"
        });
    },
    showReg: function() {
        "" != this.data.provicevalue ? "" != this.data.cityvalue ? this.setData({
            regshow: !0
        }) : wx.showToast({
            title: "请选择市级区域",
            icon: "none"
        }) : wx.showToast({
            title: "请选择省级区域",
            icon: "none"
        });
    },
    showStr: function() {
        "" != this.data.provicevalue ? "" != this.data.cityvalue ? "" != this.data.regionvalue ? this.setData({
            streetshow: !0
        }) : wx.showToast({
            title: "请选择区/县级区域",
            icon: "none"
        }) : wx.showToast({
            title: "请选择市级区域",
            icon: "none"
        }) : wx.showToast({
            title: "请选择省级区域",
            icon: "none"
        });
    },
    isStreetShow: function(t) {
        var a = this;
        if (3 == this.data.selectLevel.tag) {
            var i = e.getNetAddresss("member.memberAddress.street");
            i += "&district_id=" + t, e._getNetWork({
                url: i,
                success: function(t) {
                    1 === t.data.result ? (console.log(t.data, "数据"), a.setData({
                        stroptions: t.data.data,
                        strshow: !0
                    })) : (a.setData({
                        strshow: !1
                    }), wx.showToast({
                        title: t.data.msg,
                        icon: "none"
                    }));
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    selectStrionHandle: function(t) {
        var e = t.target.dataset.item || t.currentTarget.dataset.item;
        this.setData({
            districtObject: e,
            streetvalue: e.areaname,
            streetshow: !1
        });
    },
    onshow: function() {
        this.setData({
            selshow: !0
        });
    },
    onClickLeft: function() {
        this.setData({
            selshow: !1,
            proshow: !1,
            cityshow: !1,
            regshow: !1,
            streetshow: !1,
            agreementShow: !1
        });
    },
    getlevelVal: function(t) {
        this.setData({
            selectLevel: t.target.dataset.item || t.currentTarget.dataset.item
        }), this.setData({
            selshow: !1
        });
        var e = this.data.selectLevel;
        "0" == e.tag ? this.setData({
            prozoneshow: !0,
            cityzoneshow: !1,
            regzoneshow: !1,
            strshow: !1
        }) : "1" == e.tag ? this.setData({
            prozoneshow: !0,
            cityzoneshow: !0,
            regzoneshow: !1,
            strshow: !1
        }) : ("2" == e.tag || "3" == e.tag) && this.setData({
            prozoneshow: !0,
            cityzoneshow: !0,
            regzoneshow: !0,
            strshow: !1
        });
    },
    onChangeOne: function(t) {
        var e = t.detail.value;
        this.setData({
            name: e
        });
    },
    onChangeTwo: function(t) {
        var e = t.detail.value;
        this.setData({
            phone: e
        });
    },
    onChangeThree: function(t) {
        var e = t.detail.value;
        this.setData({
            username: e
        });
    },
    onChangeFour: function(t) {
        var e = t.detail.value;
        this.setData({
            password: e
        });
    }
});